<%-- To be included in trainees.jsp, no need to specify error page. --%>

<%-- Retrive a list of trainee from database. --%>

<%-- page settings. --%>
<%@ page import="java.sql.Connection"%>
<%@ page import="java.sql.DriverManager"%>
<%@ page import="java.sql.SQLException"%>
<%@ page import="java.sql.Statement"%>
<%@ page import="java.sql.PreparedStatement"%>
<%@ page import="java.sql.ResultSet"%>

<%-- Global variables declaration. --%>
<%!public final String CONNECTION_URL = "jdbc:mysql://localhost:3306/prepooltest?user=root&;password=";%>
<%!public Connection conn = null;%>
<%!public final String DRIVER = "com.mysql.jdbc.Driver"; %>

<%

	// Declare db driver class.
	Class.forName(DRIVER).newInstance();

	// Get connection with connection string.
	conn = DriverManager.getConnection(CONNECTION_URL);

	ResultSet result = null;

	result = null;

	Statement stmt = conn.createStatement();

	result = stmt.executeQuery("SELECT * FROM " + "trainee"
			+ " ORDER BY account;");		
	
	// Send object back to session. Later use them on trainees.jsp.
	
	session.setAttribute("connection", conn);	
	session.setAttribute("result", result);	
	session.setAttribute("statement", stmt);	
	
%>
